package com.dlc.shop.live.common.listener;

import com.dlc.shop.bean.event.UserDestroyEvent;
import com.dlc.shop.live.common.service.LiveRoomService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author track
 */
@Slf4j
@Component("liveUserDestroyListener")
@AllArgsConstructor
public class UserDestroyListener {

    private final LiveRoomService liveRoomService;

    /**
     * 用户注销时,删除相关数据
     */
    @EventListener(UserDestroyEvent.class)
    public void userDestroyListener(UserDestroyEvent event) {
        String userId = event.getUserId();
        liveRoomService.quitUser(userId, true);
    }
}
